package com.irdstudio.tdp.console.service.impl;

import java.util.List;
import java.util.Objects;

import com.irdstudio.tdp.console.dao.PluginContentionConfDao;
import com.irdstudio.tdp.console.dao.domain.PluginContentionConf;
import com.irdstudio.tdp.console.service.facade.PluginContentionConfService;
import com.irdstudio.tdp.console.service.vo.PluginContentionConfVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.sdk.beans.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 竟办插件配置				<p>
 * @author srvadmin
 * @date 2020-07-24
 */
@Service("pluginContentionConfServiceImpl")
public class PluginContentionConfServiceImpl implements PluginContentionConfService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PluginContentionConfServiceImpl.class);

	@Autowired
	private PluginContentionConfDao pluginContentionConfDao;
	
	/**
	 * 新增操作
	 */
	public int insertPluginContentionConf(PluginContentionConfVO inPluginContentionConfVo) {
		logger.debug("当前新增数据为:"+ inPluginContentionConfVo.toString());
		int num = 0;
		try {
			PluginContentionConf pluginContentionConf = new PluginContentionConf();
			beanCopy(inPluginContentionConfVo, pluginContentionConf);
			num = pluginContentionConfDao.insertPluginContentionConf(pluginContentionConf);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PluginContentionConfVO inPluginContentionConfVo) {
		logger.debug("当前删除数据条件为:"+ inPluginContentionConfVo);
		int num = 0;
		try {
			PluginContentionConf pluginContentionConf = new PluginContentionConf();
			beanCopy(inPluginContentionConfVo, pluginContentionConf);
			num = pluginContentionConfDao.deleteByPk(pluginContentionConf);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPluginContentionConfVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PluginContentionConfVO inPluginContentionConfVo) {
		logger.debug("当前修改数据为:"+ inPluginContentionConfVo.toString());
		int num = 0;
		try {
			PluginContentionConf pluginContentionConf = new PluginContentionConf();
			beanCopy(inPluginContentionConfVo, pluginContentionConf);
			num = pluginContentionConfDao.updateByPk(pluginContentionConf);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPluginContentionConfVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PluginContentionConfVO queryByPk(PluginContentionConfVO inPluginContentionConfVo) {
		
		logger.debug("当前查询参数信息为:"+ inPluginContentionConfVo);
		try {
			PluginContentionConf queryPluginContentionConf = new PluginContentionConf();
			beanCopy(inPluginContentionConfVo, queryPluginContentionConf);
			PluginContentionConf queryRslPluginContentionConf = pluginContentionConfDao.queryByPk(queryPluginContentionConf);
			if (Objects.nonNull(queryRslPluginContentionConf)) {
				PluginContentionConfVO outPluginContentionConfVo = beanCopy(queryRslPluginContentionConf, new PluginContentionConfVO());
				logger.debug("当前查询结果为:"+ outPluginContentionConfVo.toString());
				return outPluginContentionConfVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PluginContentionConfVO> queryAllOwner(PluginContentionConfVO pluginContentionConfVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PluginContentionConfVO> list = null;
		try {
			List<PluginContentionConf> pluginContentionConfs = pluginContentionConfDao.queryAllOwnerByPage(pluginContentionConfVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pluginContentionConfs.size());
			pageSet(pluginContentionConfs, pluginContentionConfVo);
			list = (List<PluginContentionConfVO>) beansCopy(pluginContentionConfs, PluginContentionConfVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PluginContentionConfVO> queryAllCurrOrg(PluginContentionConfVO pluginContentionConfVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PluginContentionConf> pluginContentionConfs = pluginContentionConfDao.queryAllCurrOrgByPage(pluginContentionConfVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pluginContentionConfs.size());
		List<PluginContentionConfVO> list = null;
		try {
			pageSet(pluginContentionConfs, pluginContentionConfVo);
			list = (List<PluginContentionConfVO>) beansCopy(pluginContentionConfs, PluginContentionConfVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PluginContentionConfVO> queryAllCurrDownOrg(PluginContentionConfVO pluginContentionConfVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PluginContentionConf> pluginContentionConfs = pluginContentionConfDao.queryAllCurrDownOrgByPage(pluginContentionConfVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pluginContentionConfs.size());
		List<PluginContentionConfVO> list = null;
		try {
			pageSet(pluginContentionConfs, pluginContentionConfVo);
			list = (List<PluginContentionConfVO>) beansCopy(pluginContentionConfs, PluginContentionConfVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
}
